library(tidyverse)
library(DESeq2)

counts = read.table("counts.txt",sep="\t",header=T,check.names=F, row.names = 1)
groupdata = read.table("group.txt",sep="\t",header=F,check.names=F)
rownames(groupdata) <- groupdata[,1]
group <- groupdata[groupdata$V2 %in% c("N", "T"), ]
deres <- counts[, rownames(group)]
group$V2 <- factor(group$V2, levels = c("N", "T"))
dds <- DESeqDataSetFromMatrix(
  countData = deres,
  colData = group,
  design = ~ V2)
dds <- DESeq(dds)#差异分析
resultsNames(dds)
res <- results(dds)

results <- as.data.frame(res)%>% 
  arrange(padj) %>% 
  dplyr::filter(abs(log2FoldChange) > 0, pvalue < 1)#根据自己需要

write.table(results,file = 'results.txt')

# plotCounts(dds, gene=which.min(res$padj), intgroup="condition")

